package com.yanqu.road.dao.impl.union.cross.huaben;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.union.huaben.config.UnionHuaBenConfigInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CrossUnionHuaBenConfigDaoImpl extends TempDao {

    private static String getUnionHuaBenConfigInfoSql = "select * from `t_p_guild_story` ORDER BY `id` ASC";
    public Map<Integer, Map<Integer, UnionHuaBenConfigInfo>> getUnionHuaBenConfigInfoMap() {
        Map<Integer, Map<Integer, UnionHuaBenConfigInfo>> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(getUnionHuaBenConfigInfoSql);
            rs = call.executeQuery();
            while (rs.next()) {
                UnionHuaBenConfigInfo data = new UnionHuaBenConfigInfo();
                data.setId(rs.getInt("id"));
                data.setDegree(rs.getInt("degree"));
                data.setLevel(rs.getInt("level"));
                data.setBossHP(rs.getString("bossHP"));
                data.setMonsterHP(rs.getString("monsterHP"));
                data.setMonsterWave(rs.getString("monsterWave"));
                data.setMonsterReward(rs.getInt("monsterReward"));
                data.setBossReward(rs.getInt("bossReward"));
                data.setBossSRNum(rs.getInt("bossSRNum"));
                data.setProbability(rs.getString("probability"));
                data.setBossScore(rs.getInt("bossScore"));
                data.setMonsterScore(rs.getInt("monsterScore"));
                if(result.get(data.getDegree()) == null){
                    result.put(data.getDegree(), new ConcurrentHashMap<>());
                }
                result.get(data.getDegree()).put(data.getLevel(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
